<template>
  <div class="app-container">
    <el-row :gutter="20">
      <el-col :span="24" class="custom-title-box">
        <div class="custom-info-title">
          {{getTitleByName(nameOfPermission)}}列表查询
          <el-button link @click="delFav()" style="margin-bottom: 5px;" v-if="userFavorites?.length > 0">
            <svg-icon icon-class="stars" color="#E6A23C" />
          </el-button>
          <el-button link @click="addFav()" style="margin-bottom: 5px;" v-else>
            <svg-icon icon-class="star" />
          </el-button>
        </div>
        <div>
          <el-button v-waves type="success" icon="Search" @click="handleFilter">
            查询
          </el-button>
          <el-button icon="Refresh" @click="handleResetQuery">
            重置
          </el-button>
        </div>
      </el-col>
    </el-row>
    <div class="filter-container">
      <el-form :inline="true" ref="listQuery" :model="listQuery" class="demo-form-inline">
        <el-form-item prop="contractInitialId" label="合同">
          <Contract v-model="listQuery.contractInitialId" keyName="id" keyShow="name" placeholder="合同" title="合同查询" />
        </el-form-item>
        <!--
        <el-form-item prop="batch" label="批次号">
          <el-input v-model="listQuery.batch" placeholder="批次号" @keyup.enter="handleFilter" />
        </el-form-item>
        -->
        <el-form-item prop="changeUserId" label="变更经办人">
          <User v-model="listQuery.changeUserId" keyName="id" keyShow="name" placeholder="变更经办人" title="用户查询" :disabled="useUserStore().organization.organizationType !== '1'" />
        </el-form-item>
        <el-form-item prop="changeDepartmentId" label="变更经办人部门">
          <Organization v-model="listQuery.changeDepartmentId" keyName="id" keyShow="organizationName" placeholder="变更经办人部门" title="部门查询" :disabled="useUserStore().organization.organizationType !== '1'" />
        </el-form-item>
        <!--
        <el-form-item prop="changeReason" label="变更原因">
          <el-input v-model="listQuery.changeReason" placeholder="变更原因" @keyup.enter="handleFilter" />
        </el-form-item>
        -->
        <el-form-item prop="state" label="变更状态">
          <el-radio-group v-model="listQuery.state">
            <el-radio-button label="" key="">全部</el-radio-button>
            <el-radio-button v-for="(item,index) in getEnumList('ContractInitialChangeState')" :label="item.key" :key="index">{{item.value}}</el-radio-button>
          </el-radio-group>
        </el-form-item>
        <el-form-item prop="code" label="合同编码">
          <InputTagDialog v-model="listQuery.code" placeholder="合同编码" title="填写合同编码" />
        </el-form-item>
        <el-form-item prop="name" label="合同名称">
          <el-input v-model="listQuery.name" placeholder="合同名称" @keyup.enter="handleFilter" />
        </el-form-item>
        <el-form-item prop="type" label="合同类型">
          <ContractType v-model="listQuery.type" keyName="id" keyShow="name" placeholder="合同类型" title="合同类型查询" />
        </el-form-item>
        <el-form-item prop="contractSignerId" label="合同签订人">
          <ContractSigner v-model="listQuery.contractSignerId" keyName="id" keyShow="name" placeholder="合同签订人" title="合同签订人查询" />
        </el-form-item>
        <el-form-item prop="contractSignerDepartmentId" label="合同签订部门">
          <Organization v-model="listQuery.contractSignerDepartmentId" keyName="id" keyShow="organizationName" placeholder="签订部门" title="部门查询" />
        </el-form-item>
        <el-form-item prop="departmentId" label="负责部门">
          <Organization v-model="listQuery.departmentId" keyName="id" keyShow="organizationName" placeholder="签订部门" title="部门查询" />
        </el-form-item>
        <el-form-item prop="userId" label="负责人用户">
          <User v-model="listQuery.userId" keyName="id" keyShow="name" placeholder="负责人用户" title="用户查询" />
        </el-form-item>
        <!--
        <el-form-item prop="amount" label="合同金额">
          <el-input v-model="listQuery.amount" placeholder="合同金额" @keyup.enter="handleFilter" />
        </el-form-item>
        -->
        <el-form-item label="合同起始时间">
          <el-date-picker v-model="listQuery.contractLaunchRange"
                          value-format="YYYY-MM-DD HH:mm:ss"
                          type="datetimerange"
                          range-separator="-"
                          start-placeholder="合同起始时间(从)"
                          end-placeholder="合同起始时间(到)" />
        </el-form-item>
        <el-form-item label="合同终止时间">
          <el-date-picker v-model="listQuery.contractCompleteRange"
                          value-format="YYYY-MM-DD HH:mm:ss"
                          type="datetimerange"
                          range-separator="-"
                          start-placeholder="合同终止时间(从)"
                          end-placeholder="合同终止时间(到)" />
        </el-form-item>
      </el-form>
    </div>
    <el-row :gutter="20">
      <el-col :span="24" class="custom-title-box">
        <div class="custom-info-title">列表详情</div>
        <!--
        <div>
          <el-button v-show="checkAuthByCode('')" type="primary" icon="Download" @click="handleExport">
            导出
          </el-button>
          <el-button type="primary" icon="Edit" :disabled="!checkAuthByCode('')" @click="handleAdd">
            新增
          </el-button>
        </div>
        -->
      </el-col>
    </el-row>
    <el-divider class="el-divider--horizontal-margin" />
    <el-table v-loading="listLoading"
              :key="tableKey"
              :data="list"
              :row-style="{height: '0'}"
              :cell-style="{padding: '0'}"
              border
              fit
              highlight-current-row
              tooltip-effect="dark"
              @sort-change="handleSortChange"
              @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="39px" />
      <el-table-column align="center" type="index" label="序号" width="60px" />
      <el-table-column v-if="isDebug" align="center" label="ID" prop="id" width="60px" sortable show-overflow-tooltip />
      <!--
      <el-table-column align="center" label="合同ID" prop="contractInitialId" min-width="120px" sortable show-overflow-tooltip />
      -->
      <el-table-column align="center" label="合同编号" prop="contractInitialNo" min-width="150px" sortable show-overflow-tooltip>
        <template v-slot="{row}">{{ getIdLabel(contractInitialList, row.contractInitialId, 'code') }}</template>
      </el-table-column>
      <el-table-column align="center" label="合同名称" prop="contractInitialName" min-width="150px" sortable show-overflow-tooltip>
        <template v-slot="{row}">{{ getIdLabel(contractInitialList, row.contractInitialId, 'name') }}</template>
      </el-table-column>
      <el-table-column align="center" label="合同负责人" prop="contractUserId" min-width="120px" sortable show-overflow-tooltip>
        <template v-slot="{row}"><LabelTag :foreignList="userList" :foreignIds="row.contractUserId" :foreignLabel="'name'" /></template>
      </el-table-column>
      <!--
      <el-table-column align="center" label="批次号" prop="batch" min-width="120px" sortable show-overflow-tooltip>
        <template v-slot="{row}">{{ row.batch }}</template>
      </el-table-column>
      -->
      <el-table-column align="center" label="变更经办人" prop="changeUserId" min-width="130px" sortable show-overflow-tooltip>
        <template v-slot="{row}"><LabelTag :foreignList="userList" :foreignIds="row.changeUserId" :foreignLabel="'name'" /></template>
      </el-table-column>
      <el-table-column align="center" label="变更经办人部门" prop="changeDepartmentId" min-width="180px" sortable show-overflow-tooltip>
        <template v-slot="{row}"><LabelTag :foreignList="organizationList" :foreignIds="row.changeDepartmentId" :foreignLabel="'organizationName'" /></template>
      </el-table-column>
      <!--
      <el-table-column align="center" label="变更原因" prop="changeReason" min-width="120px" sortable show-overflow-tooltip>
        <template v-slot="{row}">{{ row.changeReason }}</template>
      </el-table-column>
      -->
      <el-table-column align="center" label="变更状态" prop="state" min-width="160px" sortable show-overflow-tooltip>
        <template v-slot="{row}">
          <EnumTag :enum-list="getEnumList('ContractInitialChangeState')" :enum-key="row.state" />
        </template>
      </el-table-column>
      <el-table-column align="center" label="合同编码" prop="code" min-width="120px" sortable show-overflow-tooltip>
        <template v-slot="{row}">{{ row.code }}</template>
      </el-table-column>
      <el-table-column align="center" label="合同名称" prop="name" min-width="120px" sortable show-overflow-tooltip>
        <template v-slot="{row}">{{ row.name }}</template>
      </el-table-column>
      <el-table-column align="center" label="合同类型" prop="type" min-width="120px" sortable show-overflow-tooltip>
        <template v-slot="{row}">{{ getIdLabel(contractTypeList, row.type, 'name') }}</template>
      </el-table-column>
      <el-table-column align="center" label="合同签订人" prop="contractSignerId" min-width="180px" sortable show-overflow-tooltip>
        <template v-slot="{row}">{{ getIdLabel(contractSignerList, row.contractSignerId, 'name') }}</template>
      </el-table-column>
      <el-table-column align="center" label="合同签订部门" prop="contractSignerDepartmentId" min-width="155px" sortable show-overflow-tooltip>
        <template v-slot="{row}"><LabelTag :foreignList="organizationList" :foreignIds="row.contractSignerDepartmentId" :foreignLabel="'organizationName'" /></template>
      </el-table-column>
      <el-table-column align="center" label="负责部门" prop="departmentId" min-width="155px" sortable show-overflow-tooltip>
        <template v-slot="{row}"><LabelTag :foreignList="organizationList" :foreign-ids="row.departmentId" :foreign-label="'organizationName'" /></template>
      </el-table-column>
      <el-table-column align="center" label="负责人用户" prop="userId" min-width="180px" sortable show-overflow-tooltip>
        <template v-slot="{row}"><LabelTag :foreignList="userList" :foreign-ids="row.userId" :foreign-label="'name'" /></template>
      </el-table-column>
      <!-- <el-table-column align="center" label="合同类型" prop="type" min-width="120px" sortable show-overflow-tooltip /> -->
      <!-- <el-table-column align="center" label="合同签订人ID" prop="contractSignerId" min-width="180px" sortable show-overflow-tooltip />
      <el-table-column align="center" label="合同签订部门ID" prop="contractSignerDepartmentId" min-width="205px" sortable show-overflow-tooltip />
      <el-table-column align="center" label="负责部门ID" prop="departmentId" min-width="155px" sortable show-overflow-tooltip />
      <el-table-column align="center" label="负责人用户ID" prop="userId" min-width="180px" sortable show-overflow-tooltip /> -->
      <el-table-column align="center" label="合同金额" prop="amount" min-width="120px" sortable show-overflow-tooltip>
        <template v-slot="{row}"><MoneyTag :money="row.amount" /></template>
      </el-table-column>
      <el-table-column align="center" label="合同起始时间" prop="contractLaunch" min-width="155px" sortable show-overflow-tooltip>
        <template v-slot="{row}">{{ row.contractLaunch?.substring(0, 10) }}</template>
      </el-table-column>
      <el-table-column align="center" label="合同终止时间" prop="contractComplete" min-width="155px" sortable show-overflow-tooltip>
        <template v-slot="{row}">{{ row.contractComplete?.substring(0, 10) }}</template>
      </el-table-column>
      <!--
      <el-table-column align="center" label="合同内容" prop="content" min-width="200px" show-overflow-tooltip>
        <template v-slot="{row}"><span v-html="row.content"></span></template>
      </el-table-column>
      -->
      <el-table-column align="center" label="创建时间" width="180px" prop="createTime" sortable show-overflow-tooltip>
        <template v-slot="{row}"><DateTag :timestamp="row.createTime" /></template>
      </el-table-column>
      <el-table-column align="center" label="最后修改时间" width="180px" prop="updateTime" sortable show-overflow-tooltip>
        <template v-slot="{row}"><DateTag :timestamp="row.updateTime" /></template>
      </el-table-column>
      <el-table-column align="center" label="操作" width="160px" fixed="right">
        <template v-slot="{row}">
          <!--
          <el-button type="primary" link @click="handleView(row)">查看</el-button>
          <el-button v-show="checkAuthByCode('')" type="primary" link @click="handleEdit(row)">编辑</el-button>
          <el-popconfirm confirm-button-text="确定"
                         cancel-button-text="取消"
                         :icon="WarningFilled"
                         icon-color="#626AEF"
                         title="您确定删除么？"
                         @confirm="handleDelete(row)"
                         v-if="checkAuthByCode('')">
            <template #reference>
              <el-button type="danger" link>删除</el-button>
            </template>
          </el-popconfirm>
          -->
          <el-button type="success" link @click="handleApprove(row)">审批流程</el-button>
          <el-popconfirm confirm-button-text="确定"
                         cancel-button-text="取消"
                         :icon="InfoFilled"
                         icon-color="#626AEF"
                         title="您确定撤回么？"
                         @confirm="handleRevocation(row)"
                         v-if="checkAuthByCode('') && ['1'].includes(row.state)">
            <template #reference>
              <el-button type="danger" link>撤回</el-button>
            </template>
          </el-popconfirm>
        </template>
      </el-table-column>
    </el-table>
    <pagination v-model:total="total" v-model:page="listQuery.pageNum" v-model:limit="listQuery.pageSize" @pagination="getList" />
    <el-dialog v-model="dialogVisible" :title="dialogTypeTitle" width="70%" top="2vh">
      <el-form class="my-form" ref="obj" :model="obj" :rules="rules" label-position="right" :disabled="dialogType === 'view'" label-width="auto" label-suffix="：">
        <el-form-item v-show="isDebug" label="ID">
          <text>{{ obj.id }}</text>
        </el-form-item>
        <el-form-item label="合同ID" prop="contractInitialId">
          <el-input v-model="obj.contractInitialId" type="number" placeholder="请输入合同ID" />
        </el-form-item>
        <!--
        <el-form-item label="批次号" prop="batch">
          <el-input v-model="obj.batch" placeholder="请输入批次号，最多输入20个字符" />
        </el-form-item>
        -->
        <el-form-item label="变更经办人" prop="changeUserId">
          <el-input v-model="obj.changeUserId" type="number" placeholder="请输入变更经办人" />
        </el-form-item>
        <el-form-item label="变更经办人部门" prop="changeDepartmentId">
          <el-input v-model="obj.changeDepartmentId" type="number" placeholder="请输入变更经办人部门" />
        </el-form-item>
        <el-form-item label="变更原因" prop="changeReason">
          <el-input v-model="obj.changeReason" :autosize="{ minRows: 2, maxRows: 5}" type="textarea" />
        </el-form-item>
        <el-form-item label="合同编码" prop="code">
          <el-input v-model="obj.code" placeholder="请输入合同编码，最多输入100个字符" />
        </el-form-item>
        <el-form-item label="合同名称" prop="name">
          <el-input v-model="obj.name" placeholder="请输入合同名称，最多输入200个字符" />
        </el-form-item>
        <el-form-item label="合同类型" prop="type">
          <el-input v-model="obj.type" type="number" placeholder="请输入合同类型" />
        </el-form-item>
        <el-form-item label="合同签订人ID" prop="contractSignerId">
          <el-input v-model="obj.contractSignerId" type="number" placeholder="请输入合同签订人ID" />
        </el-form-item>
        <el-form-item label="合同签订部门ID" prop="contractSignerDepartmentId">
          <el-input v-model="obj.contractSignerDepartmentId" type="number" placeholder="请输入合同签订部门ID" />
        </el-form-item>
        <el-form-item label="负责部门ID" prop="departmentId">
          <el-input v-model="obj.departmentId" type="number" placeholder="请输入负责部门ID" />
        </el-form-item>
        <el-form-item label="负责人用户ID" prop="userId">
          <el-input v-model="obj.userId" type="number" placeholder="请输入负责人用户ID" />
        </el-form-item>
        <el-form-item label="合同金额" prop="amount">
          <el-input-number v-model="obj.amount" placeholder="请输入合同金额" />
        </el-form-item>
        <el-form-item label="合同起始时间" prop="contractLaunch">
          <el-date-picker v-model="obj.contractLaunch" placeholder="请输入合同起始时间" type="datetime" value-format="YYYY-MM-DD HH:mm:ss" />
        </el-form-item>
        <el-form-item label="合同终止时间" prop="contractComplete">
          <el-date-picker v-model="obj.contractComplete" placeholder="请输入合同终止时间" type="datetime" value-format="YYYY-MM-DD HH:mm:ss" />
        </el-form-item>
        <el-form-item label="合同内容" prop="content">
          <span v-html="obj.content"></span>
        </el-form-item>
        <el-form-item label="创建时间">
          <text>{{ obj.createTime || '自动生成' }}</text>
        </el-form-item>
        <el-form-item label="最后修改时间">
          <text>{{ obj.updateTime || '自动生成' }}</text>
        </el-form-item>
        <el-form-item v-show="isDebug" label="数据版本">
          <text>{{ obj.version }}</text>
        </el-form-item>
      </el-form>
      <div style="text-align:right;">
        <el-button type="info" icon="Close" @click="dialogVisible=false">关闭</el-button>
        <el-button type="primary" icon="Check" v-show="dialogType !== 'view'" @click="doConfirm('obj')">确定</el-button>
      </div>
    </el-dialog>
    <el-dialog v-model="dialogApproveVisible" title="审批流程" width="55%" top="2vh">
      <approveTimeline :businessType="approveOrderBusinessTypes().contractChange" :businessId="obj.id" />
      <div style="text-align:right;margin: 1.875rem 0;">
        <el-button type="danger" @click="dialogApproveVisible=false">关闭</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import baseConfig from '@/mixins/baseConfig'
import {doGet, doPost, doPut, doDelete, doGetDownload} from '@/config/http'
import {
  alertErrorMsg,
  approveOrderBusinessTypes,
  customValidator,
  getListPageSize,
  notifySuccess,
  showIdLabel
} from '@/config/common'
import InputTagDialog from '@/components/InputTag/inputTagDialog.vue';
import SvgIcon from '@/components/SvgIcon/index.vue';
import Organization from "@/views/components/base/selectOrganization.vue";
import Contract from "@/views/components/contract/selectContract.vue";
import User from "@/views/components/base/selectUser.vue";
import ContractType from "@/views/components/contract/selectContractType.vue";
import ContractSigner from "@/views/components/contract/selectContractSigner.vue";
import {getUserId} from "@/config/cookie";
import approveTimeline from "@/views/components/base/approveTimeline.vue";
import useUserStore from "@/store/modules/user";
import initListStore from '@/store/modules/initList'

const emptyObj = {
  contractInitialId: null, // 合同ID
  batch: null, // 批次号
  changeUserId: null, // 变更经办人
  changeDepartmentId: null, // 变更经办人部门
  changeReason: null, // 变更原因
  code: null, // 合同编码
  name: null, // 合同名称
  type: null, // 合同类型
  contractSignerId: null, // 合同签订人ID
  contractSignerDepartmentId: null, // 合同签订部门ID
  departmentId: null, // 负责部门ID
  userId: null, // 负责人用户ID
  amount: null, // 合同金额
  contractLaunch: null, // 合同起始时间
  contractComplete: null, // 合同终止时间
  content: null, // 合同内容
  id: null,
  createBy: null,
  createTime: null,
  updateBy: null,
  updateTime: null,
  deleted: null,
  version: null,
}

export default {
  name: 'contractInitialChange_nocache',
  components: {approveTimeline, ContractSigner, ContractType, User, Organization, Contract, SvgIcon, InputTagDialog},
  mixins: [baseConfig],
  data() {
    const svc = 'icims-api'
    return {
      svc,
      obj: Object.assign({}, emptyObj),
      routes: [],
      nameOfPermission: null,
      dialogVisible: false,
      dialogType: 'add',
      dialogTypeTitle: '新增',
      checkStrictly: false,
      defaultProps: {
        children: 'children',
        label: 'title'
      },
      tableKey: 0,
      list: null,
      total: 0,
      listLoading: false,
      listQuery: {
        pageNum: 1,
        pageSize: 10,
        sortField: 'id',
        sortType: 'desc',
        contractInitialId: null,
        batch: null,
        changeUserId: useUserStore().organization.organizationType !== '1' ? getUserId() : '',
        changeDepartmentId: useUserStore().organization.organizationType !== '1' ? useUserStore().organization.id : '',
        changeReason: null,
        code: null,
        name: null,
        type: null,
        contractSignerId: null,
        contractSignerDepartmentId: null,
        departmentId: null,
        userId: null,
        amount: null,
        contractLaunchStart: null,
        contractLaunchEnd: null,
        contractLaunchRange: [],//
        contractCompleteStart: null,
        contractCompleteEnd: null,
        contractCompleteRange: [],//
        createTimeStart: null,
        createTimeEnd: null,
        updateTimeStart: null,
        updateTimeEnd: null,
      },
      selectionList: [],
      dialogFormVisible: false,
      dialogStatus: '',
      dialogApproveVisible: false,
      rules: {
        contractInitialId: [{ required: true, validator: customValidator, min: 1, max: 20, label: '合同ID', trigger: ['blur', 'change'] }],
        batch: [{ required: false, validator: customValidator, min: 0, max: 20, label: '批次号', trigger: ['blur', 'change'] }],
        changeUserId: [{ required: false, validator: customValidator, min: 0, max: 20, label: '变更经办人', trigger: ['blur', 'change'] }],
        changeDepartmentId: [{ required: false, validator: customValidator, min: 0, max: 20, label: '变更经办人部门', trigger: ['blur', 'change'] }],
        changeReason: [{ required: false, validator: customValidator, min: 0, max: 1000, label: '变更原因', trigger: ['blur', 'change'] }],
        code: [{ required: true, validator: customValidator, min: 1, max: 100, label: '合同编码', trigger: ['blur', 'change'] }],
        name: [{ required: true, validator: customValidator, min: 1, max: 200, label: '合同名称', trigger: ['blur', 'change'] }],
        type: [{ required: false, validator: customValidator, min: 0, max: 20, label: '合同类型', trigger: ['blur', 'change'] }],
        contractSignerId: [{ required: false, validator: customValidator, min: 0, max: 20, label: '合同签订人ID', trigger: ['blur', 'change'] }],
        contractSignerDepartmentId: [{ required: false, validator: customValidator, min: 0, max: 20, label: '合同签订部门ID', trigger: ['blur', 'change'] }],
        departmentId: [{ required: false, validator: customValidator, min: 0, max: 20, label: '负责部门ID', trigger: ['blur', 'change'] }],
        userId: [{ required: false, validator: customValidator, min: 0, max: 20, label: '负责人用户ID', trigger: ['blur', 'change'] }],
        amount: [{ required: false, validator: customValidator, min: 0, max: 13, label: '合同金额', trigger: ['blur', 'change'] }],
        contractLaunch: [{ required: false, validator: customValidator, min: 0, max: 20, label: '合同起始时间', trigger: ['blur', 'change'] }],
        contractComplete: [{ required: false, validator: customValidator, min: 0, max: 20, label: '合同终止时间', trigger: ['blur', 'change'] }],
        content: [{ required: false, validator: customValidator, min: 0, max: 0, label: '合同内容', trigger: ['blur', 'change'] }],
      },
      userList: initListStore().userList,
      organizationList: initListStore().organizationList,
      contractInitialList: [],
      contractSignerList: initListStore().contractSignerList,
      contractTypeList: initListStore().contractTypeList,
      currentUserId: getUserId(),
    }
  },
  computed: {
    routesData() {
      return this.routes
    },
  },
  async created() {
    this.nameOfPermission = 'contractInitialChange'
    this.getFavorite(this.nameOfPermission)?.then(res => this.userFavorites = res)
    await this.getList()
  },
  methods: {
    useUserStore,
    approveOrderBusinessTypes,
    showIdLabel,
    async initList() {
      // let p1 = doGet(this.svc, '/user/page', {pageSize: getListPageSize()}, false) // 用户
      // let p2 = doGet(this.svc, '/contract-type/page', {pageSize: getListPageSize()}, false)
      // let p3 = doGet(this.svc, '/organization/page', {pageSize: getListPageSize()}, false)
      // let p4 = doGet(this.svc, '/user/page', {pageSize: getListPageSize()}, false)
      // let p5 = doGet(this.svc, '/contract-signer/page', {pageSize: getListPageSize()}, false)
      // let resArray = await Promise.all([p1, p2, p3, p4, p5])
      // this.userList = resArray[0]['records']
      // this.contractTypeList = resArray[1]['records']
      // this.organizationList = resArray[2]['records']
      // this.userList = resArray[3]['records']
      // this.contractSignerList = resArray[4]['records']
      let contractIds = this.list.map(item => item.contractInitialId)
      if (contractIds.length > 0) {
        this.contractInitialList = await doGet(this.svc, '/contract-initial/ids', {ids: contractIds.join(',')}, false) // 初始合同
        this.list.map(item1 => {
          this.contractInitialList.map(item2 => {
            if (item1.contractInitialId === item2.id) {
              item1.contractUserId = item2.userId
            }
          })
        })
      }
    },
    async getList() {
      this.listLoading = true
      this.listQuery.contractLaunchStart = ''
      this.listQuery.contractLaunchEnd = ''
      if (this.listQuery.contractLaunchRange) {
        this.listQuery.contractLaunchStart = this.listQuery.contractLaunchRange[0]
        this.listQuery.contractLaunchEnd = this.listQuery.contractLaunchRange[1]
      }
      this.listQuery.contractCompleteStart = ''
      this.listQuery.contractCompleteEnd = ''
      if (this.listQuery.contractCompleteRange) {
        this.listQuery.contractCompleteStart = this.listQuery.contractCompleteRange[0]
        this.listQuery.contractCompleteEnd = this.listQuery.contractCompleteRange[1]
      }
      let res = await doGet(this.svc, '/contract-initial-change/page', this.listQuery)
      this.listLoading = false
      this.list = res['records']
      this.total = parseInt(res['total'])
      this.listLoading = false
      await this.initList()
    },
    handleResetQuery() {
      this.resetForm("listQuery")
      this.listQuery.contractLaunchStart = ''
      this.listQuery.contractLaunchEnd = ''
      this.listQuery.contractLaunchRange = []
      this.listQuery.contractCompleteStart = ''
      this.listQuery.contractCompleteEnd = ''
      this.listQuery.contractCompleteRange = []
    },
    handleFilter() {
      this.listQuery.pageNum = 1
      this.getList()
    },
    handleModifyStatus(row, status) {
      this.$message({
        message: '操作Success',
        type: 'success'
      })
      row.status = status
    },
    handleSelectionChange(data) {
      this.selectionList = data
    },
    handleSortChange(data) {
      const { prop, order } = data
      this.listQuery.sortField = prop
      this.listQuery.sortType = order === 'ascending' ? 'asc' : 'desc'
      this.handleFilter()
    },
    handleEdit(row) {
      this.dialogType = 'edit'
      this.dialogTypeTitle = '编辑'
      this.dialogVisible = true
      this.checkStrictly = true
      this.obj = Object.assign({}, row)
    },
    handleView(row) {
      this.dialogType = 'view'
      this.dialogTypeTitle = '详情'
      this.dialogVisible = true
      this.checkStrictly = false
      this.obj = Object.assign({}, row)
    },
    handleAdd() {
      this.dialogType = 'add'
      this.dialogTypeTitle = '新增'
      this.dialogVisible = true
      this.checkStrictly = true
      this.obj = Object.assign({}, emptyObj)
    },
    handleExport() {
      doGetDownload(this.svc, '/contract-initial-change/export', this.listQuery)
    },
    handleDelete(row) {
      doDelete(this.svc, `/contract-initial-change/${row.id}`, {}).then(() => {
        notifySuccess('操作成功')
        this.getList()
        this.dialogVisible = false
      })
    },
    async doConfirm(formName) {
      let v = await this.$refs[formName].validate().catch((err)=>{return err})
      if (v !== true) {
        alertErrorMsg('表单验证不通过，请检查数据。')
        return
      }
      switch (this.dialogType) {
        case 'add': {
          doPost(this.svc, '/contract-initial-change/add', this.obj).then(() => {
            notifySuccess('新增成功')
            this.getList()
            this.dialogVisible = false
          })
          break
        }
        case 'edit': {
          doPut(this.svc, '/contract-initial-change/modify', this.obj).then(() => {
            notifySuccess('修改成功')
            this.getList()
            this.dialogVisible = false
          })
          break
        }
      }
    },
    handleRevocation(row) {
      doPost(this.svc, `/customContractInitial/revocationContractInitialChange/${row.id}`, {}, true).then(() => {
        notifySuccess('撤回成功')
        this.getList()
      })
    },
    handleApprove(row) {
      this.obj = Object.assign({}, row)
      this.dialogApproveVisible = true
    },
  }
}
</script>
